package effect
{
	
	import effect.image.Reflect;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.*;
	import flash.geom.*;
	import flash.net.*;
	
	[SWF(backgroundColor="#000000", width="1280", height="960")]
	/**
	 * 图片墙 
	 * @author KimWang
	 * 
	 */
	public class PictureWall extends Sprite
	{
		private var contain:Sprite=new Sprite();//创建容器
		private var list:Array=new Array();//用于图片管理的数
		private var count:int=0;
		private var imageList:Array=new Array();
		
		public function PictureWall()
		{
			init();
			init_loadImage();
		}
		
		private function init():void
		{
			addChild(contain);
			contain.x=0;
			contain.y=100;
			contain.z=10;			
			root.transform.perspectiveProjection.fieldOfView=60;//初始化透视角度			
		}
		
		//加载外部图片
		private function init_loadImage():void
		{
			
			addImages("./image/img/pic (1).jpg","./image/img/pic (2).jpg","./image/img/pic (3).jpg","./image/img/pic (4).jpg",
				"./image/img/pic (5).jpg","./image/img/pic (6).jpg","./image/img/pic (7).jpg","./image/img/pic (8).jpg",
				"./image/img/pic (9).jpg","./image/img/pic (10).jpg","./image/img/pic (11).jpg","./image/img/pic (12).jpg",
				"./image/img/pic (13).jpg","./image/img/pic (14).jpg","./image/img/pic (15).jpg","./image/img/pic (16).jpg",
				"./image/img/pic (17).jpg","./image/img/pic (18).jpg","./image/img/pic (19).jpg","./image/img/pic (20).jpg",
				"./image/img/pic (21).jpg","./image/img/pic (22).jpg","./image/img/pic (23).jpg","./image/img/pic (24).jpg",
				"./image/img/pic (25).jpg","./image/img/pic (26).jpg","./image/img/pic (27).jpg","./image/img/pic (28).jpg",
				"./image/img/pic (29).jpg","./image/img/pic (30).jpg","./image/img/pic (31).jpg","./image/img/pic (32).jpg");			
		}
		
		
		//创建二维阵列分布4x8
		private function createSprite(array:Array):void
		{
			var k:int=0;
			for (var i:int=0; i<4; i++)
			{
				for (var j:int=0; j<8; j++)
				{
					var myphoto:MovieClip=new MovieClip();
					contain.addChild(myphoto);
					myphoto.addChild(array[k]);
					//list.push(myphoto);
					myphoto.x=myphoto.width*j+10*j;
					if(i==3)
					{
						var r1:Reflect = new Reflect({mc:myphoto, alpha:30, ratio:80, distance:0, updateTime:-1, reflectionDropoff:0});
						myphoto.y=myphoto.height*i/2+10*i;
					}
					else
					{
						
						myphoto.y=myphoto.height*i+10*i;
					}
					k++;
				}
				
			}
			contain.rotationY=-45;//偏移45度
		}
		
		//添加外部图片，偷懒的做法 
		private function addImages(...args):void
		{
			count=args.length;
			for (var i:int=0; i<args.length; i++)
			{
				var loader:Loader=new Loader();
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
				loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onError);
				loader.load(new URLRequest(args[i]));
			}
		}
		private function onComplete(event:Event):void
		{
			var bitmap:Bitmap=event.currentTarget.content as Bitmap;
			imageList.push(bitmap);
			event.currentTarget.removeEventListener(Event.COMPLETE,onComplete);
			event.currentTarget.removeEventListener(IOErrorEvent.IO_ERROR,onError);
			count--;
			if (count==0)
			{
				createSprite(imageList);
			}
			
		}
		private function onError(event:Event):void
		{
			throw new Error("路径错误");
		}
		
	}
	
	
	
}